<?php
/**
 * Contus Support Interactive.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file PRICE COUNTDOWN-LICENSE.txt.
 *
 * =================================================================
 *                 MAGENTO EDITION USAGE NOTICE
 * =================================================================
 * This package designed for Magento 1.4.x, 1.5.x, 1.6.x and 1.7.x COMMUNITY edition
 * Contus Support does not guarantee correct work of this package
 * on any other Magento edition except Magento 1.4.x, 1.5.x, 1.6.x and 1.7.x COMMUNITY edition.
 * =================================================================
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
/* Count for timer calculation declared here */
$count = 1;
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');

/* Admin Controllers for timer are declared here */
$timer_active = Mage::getStoreConfig('timer/general/activate_apptha_timer');
$timer_head_active = Mage::getStoreConfig('timer/general/activate_apptha_heading');
$timer_desc_active = Mage::getStoreConfig('timer/general/activate_apptha_description');
$timer_color = Mage::getStoreConfig('timer/apptha_timer_color/text');
$desc_color = Mage::getStoreConfig('timer/apptha_timer_color/description');
$head_color = Mage::getStoreConfig('timer/apptha_timer_color/heading_text_color');
$timer_head = Mage::getStoreConfig('timer/general/heading');
?>

<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>

<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product):?>
<?php $toDate = $_product->getSpecialTODate(); ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">

<?php // Product Image ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<div class="product-shop">
<div class="f-fix">
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>

<!--Condition for Timer Controllers goes here-->
<?php if($timer_active == 1) :?>
<?php if($_product->getPrice() > $_product->getSpecialPrice()) : ?>
<?php if($_product->getSpecialPrice()!= 0 || $_product->getSpecialPrice()!= "" ) :?>
<?php if($timer_head_active == 'showall' || $timer_head_active == 'listpage' && $timer_head_active!='hideall' && $timer_head!= '') : ?>
                        <div id="heading<?php echo $count; ?>" style="color:#<?php echo $head_color; ?>; font-size: 14px; font-weight:bold;padding-top:0px;clear: both;"><?php echo $timer_head ?></div>
<?php endif; ?>
                        <div id="countbox_<?php echo $count; ?>" class="timer-list"></div>
<?php if($timer_desc_active == 'showall' || $timer_desc_active == 'listpage' && $timer_desc_active!='hideall') : ?>
                        <div class='clear'></div><div class='timerdate' id="caption<?php echo $count; ?>"><span class='hour' style='margin:1px 23px 0 4px'><?php echo $this->__('D') ?></span><span class='hour' style='margin:1px 19px 0 6px'><?php echo $this->__('H') ?></span><span class='min'  style='margin:1px 20px 0 7px'><?php echo $this->__('M') ?></span><span class='sec' style='margin:1px 0 0 6px'><?php echo $this->__('S') ?></span></div>
<?php endif;endif;endif;endif; ?>

<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<div class="desc std">
<?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
 <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
</div>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
<?php if($_product->getPrice() > $_product->getSpecialPrice()) : ?>
<?php if($_product->getSpecialPrice()!= 0 || $_product->getSpecialPrice()!= "" ) :?>
        <script type="text/javascript">
            var dthen<?php echo $count; ?> = new Date("<?php echo Date("m/d/y", strtotime($toDate)).' 11:59:00 PM'; ?>");
            start = "<?php echo Date("m/d/y h:i:s A", strtotime(Mage_Core_Model_Locale::date(null, null, "en_US", true))); ?>";
            start_date = Date.parse(start);
            var dnow<?php echo $count; ?> = new Date(start_date);
            if(CountStepper>0)
                ddiff= new Date((dnow<?php echo $count; ?>)-(dthen<?php echo $count; ?>));
            else
                ddiff = new Date((dthen<?php echo $count; ?>)-(dnow<?php echo $count; ?>));
            gsecs<?php echo $count; ?> = Math.floor(ddiff.valueOf()/1000);
            var iid<?php echo $count; ?> = "countbox_<?php echo $count; ?>";
            CountBack(gsecs<?php echo $count; ?>,"countbox_"+j, j);
            j++;
        </script>
<?php $count = $count + 1; ?>
 <?php endif;endif; ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>

<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>

<?php // Grid Mode ?>

<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount();?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php $toDate = $_product->getSpecialTODate();?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>

<!--Condition for Timer Controllers goes here-->
<?php if($timer_active == 1) :?>
<?php if($_product->getPrice() > $_product->getSpecialPrice()) : ?>
<?php if($_product->getSpecialPrice()!= 0 || $_product->getSpecialPrice()!= "" ) :?>
<?php if($timer_head_active == 'showall' || $timer_head_active == 'listpage' && $timer_head_active!='hideall' && $timer_head!= '') : ?>
                        <div id="heading<?php echo $count; ?>" style="color:#<?php echo $head_color; ?>; font-size: 14px; font-weight:bold;padding-top:3px;clear: both;"><?php echo $timer_head ?></div>
<?php endif; ?>
                        <div id="countbox_<?php echo $count; ?>" class="timer-grid"></div>
<?php if($timer_desc_active == 'showall' || $timer_desc_active == 'listpage' && $timer_desc_active!='hideall') : ?>
                        <div class='clear'></div><div class='timerdate' id="caption<?php echo $count; ?>"><span class='hour' style='margin:1px 23px 0 8px'><?php echo $this->__('D') ?></span><span class='hour' style='margin:1px 24px 0 1px'><?php echo $this->__('H') ?></span><span class='min'  style='margin:1px 21px 0 3px'><?php echo $this->__('M') ?></span><span class='sec' style='margin:1px 0 0 6px'><?php echo $this->__('S') ?></span></div>
<?php endif;endif;endif;endif; ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

<?php if($_product->getPrice() > $_product->getSpecialPrice()) : ?>
<?php if($_product->getSpecialPrice()!= 0 || $_product->getSpecialPrice()!= "" ) :?>
        <script type="text/javascript">
            var dthen<?php echo $count; ?> = new Date("<?php echo Date("m/d/y", strtotime($toDate)).' 11:59:00 PM'; ?>");
            start = "<?php echo Date("m/d/y h:i:s A", strtotime(Mage_Core_Model_Locale::date(null, null, "en_US", true))); ?>";
            start_date = Date.parse(start);
            var dnow<?php echo $count; ?> = new Date(start_date);
            if(CountStepper>0)
                ddiff= new Date((dnow<?php echo $count; ?>)-(dthen<?php echo $count; ?>));
            else
                ddiff = new Date((dthen<?php echo $count; ?>)-(dnow<?php echo $count; ?>));
            gsecs<?php echo $count; ?> = Math.floor(ddiff.valueOf()/1000);

            var iid<?php echo $count; ?> = "countbox_<?php echo $count; ?>";
            CountBack(gsecs<?php echo $count; ?>,"countbox_"+j, j);
            j++;
        </script>
<?php $count = $count + 1; ?>
<?php endif;endif; ?>

<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>

<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php endif; ?>

<!--Dynamic style changes goes here-->
<style>
.timer-grid{float: left;width: 100%;padding: 0;color: #<?php echo $timer_color; ?>;font-size: 18px;font-family: arial;font-weight: bold;}
.timer-list{float: left;width: 100%;padding: 0;color: #<?php echo $timer_color; ?>;font-size: 18px;font-family:arial;font-weight: bold;}
.timerdate{float: left;width: 100%;padding:0 0 3px 0;color: #<?php echo $desc_color; ?>;font-size: 12px;}
</style>